<template>
	<view class="u-page">
	<!-- 	<u-calendar :show="show"></u-calendar> -->
		<zb-dropdown-menu style="width: 100%" active-color="#00aaff">
			<zb-dropdown-item name="first" :options="option" v-model="value1" @change="change1"></zb-dropdown-item>
			<zb-dropdown-item name="two" :options="option2" v-model="value2" @change="change2"></zb-dropdown-item>
			<zb-dropdown-item name="three" :options="option3" v-model="value3" @change="change3"></zb-dropdown-item>
			<zb-dropdown-item name="four" :options="option4" v-model="value4" @change="change4"></zb-dropdown-item>
		</zb-dropdown-menu>
			<u-calendar :show="show" :mode="mode" :monthNum="monthNum" :maxDate="maxDate" :minDate="minDate" :defaultDate="defaultDate" @confirm="confirm" @close="datedel"></u-calendar>
			<u-cell-group>
					<u-cell icon="file-text" :border="false" :title="title"></u-cell>
				</u-cell-group>
		<div v-if="list1<1">
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png">
			</u-empty>
		</div>
		<div v-else>
			<u-list @scrolltolower="scrolltolower" style="zoom: 110%;">
				<u-list-item v-for="(item, index) in indexList" :key="index">
					<!-- 	<view class="uni-card__header-extra" @click="onClick('extra')">
						<text class="uni-card__header-extra-text">{{ extra }}</text>
					</view> -->
					<uni-card :title="item.equipment" sub-title="设备名" @click="more(index,item.id,$event)">
						<text>单号：</text><text>{{item.cardno}}</text>
						<br>
						<text>报修人：</text><text>{{item.signer}}</text>
						<br>
						<text>维修人：</text><text>{{item.repairer}}</text>
						<br>
						<div v-if="item.rank==1">
							<text>维修类型：</text><text>车辆服务设施维修</text>
						</div>
						<div v-if="item.rank==2">
							<text>维护类型：</text><text>快速公交站台维修</text>
						</div>
						<div v-if="item.rank==3">
							<text>维护类型：</text><text>场站设备设施维修</text>
						</div>
						<div v-if="item.rank==4">
							<text>维护类型：</text><text>客运站设施维修</text>
						</div>
						<div v-if="item.rank==5">
							<text>维护类型：</text><text>故障报修</text>
						</div>
						<!-- 	<text>维护等级：</text><text>{{item.category}}级</text>
							<br> -->
						<text>所属车队：</text><text>{{item.org_name}}</text>
						<br>
						<text>报修时间：</text><text>{{$u.timeFormat(item.create_time, 'yyyy年mm月dd日')}}</text>
						<br>
						<text>审核时间：</text><text>{{$u.timeFormat(item.finish_time, 'yyyy年mm月dd日')}}</text>
						<div v-if="group_id==2">
						<text>工时：</text><text>{{item.sum_count}}</text>
						</div>
						<div v-if="item.condition==0">

							<text>状态：</text>
							<view style="width: 3rem;display: inline-block;"><u-tag text="未处理" plain
									size="mini"></u-tag></view>

							<!-- <text>审核状态：</text><u-tag text="已完成待审核" type="warning" plain size="mini" style="width: 5.3rem;display: inline-block;"></u-tag> -->
						</div>
						<div v-else-if="item.condition==1">
							<text>状态：</text>
							<view class="" style="width: 3rem;display: inline-block;"><u-tag text="待审核" plain
									size="mini"></u-tag></view>
						</div>
						<div v-else-if="item.condition==2">
							<text>状态：</text>
							<view class="" style="width: 3m;display: inline-block;"><u-tag text="待件" type="warning"
									plain size="mini"></u-tag></view>
						</div>
						<div v-else-if="item.condition==3">
							<text>状态：</text>
							<view class="" style="width: 4.5em;display: inline-block;"><u-tag text="审核通过" type="success"
									plain size="mini"></u-tag></view>
						</div>
						<div v-else-if="item.condition==4">
							<text>状态：</text>
							<view class="" style="width: 5.5em;display: inline-block;"><u-tag text="审核不通过" type="error"
									plain size="mini"></u-tag></view>
						</div>
					</uni-card>
				</u-list-item>
			</u-list>
		</div>

		<!-- 	<u-tabbar
			:value="value6"
			@change="name => value6 = name"
			:fixed="true"
			:placeholder="true"
			:safeAreaInsetBottom="true"
		>
			<u-tabbar-item text="培训列表" icon="play-right" ></u-tabbar-item>
			<u-tabbar-item text="个人中心" icon="account" ></u-tabbar-item>
		</u-tabbar> -->
	</view>

</template>

<script>
	import indexList from '../../uni_modules/uview-ui/libs/config/props/indexList';
	import store from '@/store/index.js'
	import {
		onLoad
	} from '../../uni_modules/uview-ui/libs/mixin/mixin';
	export default {
		data() {
			return {
				indexList: [],
				option: [{
						text: '全部',
						value: ''
					},
					{
						text: '未处理',
						value: 0
					},
					{
						text: '待审核',
						value: 1
					},
					{
						text: '待件',
						value: 2
					},
					{
						text: '审核通过',
						value: 3
					},
					{
						text: '审核不通过',
						value: 4
					},
				],
				option2: [{
						text: '日期降序',
						value: "create_time desc"
					},
					{
						text: '日期升序',
						value: "create_time asc"
					},
				],
				option3: [{
						text: '所有车队',
						value: ""},
					
				],
				optionx: [
					{
						text: '未处理',
						value: 0
					},
				],
				option4: [	{
						text: '所有日期',
						value: "所有日期"
					},
					{
						text: '自定义日期范围',
						value: "自定义日期范围"
					},
					
				],
				title:'',
				value1: '',
				value2: '',
				value3: '',
				value4: '',
				time:'',
				value6: 0,
				page: 0,
				list1: 1,
				userid: '',
				group_id:'',
				sever:store.state.sever,
				show: false,
				mode: 'range',
				monthNum:'13',
				minDate:'2022-06-01',
				maxDate: uni.$u.timeFormat(this.timestamp, 'yyyy-mm-dd'),
				defaultDate:[uni.$u.timeFormat(this.timestamp, 'yyyy-mm-dd')],
				// name: uni.getStorageSync("userinfo.nickname"),
				//             list: ['未上传', '待审核', '已结束'],
				// curNow: 0
			}
		},
		// created(){
		// 	alert(123);
		// },
		onLoad(option) {
			this.userid=store.state.userinfo.userid;
			this.group_id=store.state.userinfo.group_id;
			// this.checklogin();
		if(option.all=="all"&&this.group_id==2){
						this.option=this.optionx;
						console.log(3306)
					}
			this.all=option.all;
			this.list();
			this.loadmore();
		},
		onShow: function(){
			uni.$once('query', (query) => {
				//console.log(query);
				this.indexList[query.index].condition = query.condition;
			});
		},
		// onShow(){
		// 	this.loadmore();
		// 	},
		mounted() {
			
			this.value1 = this.option[0]['value'];
			this.value2 = this.option2[0]['value'];
			this.value3 = this.option3[0]['value'];
			this.value4 = this.option4[0]['value'];
			// alert(this.list1);
			
		},
		methods: {
			list(){
				uni.$u.http.get('https://wdzbx.zsbike.com.cn:10787/api.v1/org', ).then(res => {
					if (res.data.Status == 1) {
						let arr = res.data.Data;
						for (let item of arr) {
							this.option3.push(item);
						}
					} 
			 })
			},
			confirm(e) {
				this.show=false;
				this.time=[Date.parse(e[0])/1000,Date.parse(e[e.length-1])/1000];
				this.time=this.time.join();
				this.search();
			},
			datedel(){
				this.show=false;
			},
			more(index, id, e) {
				uni.navigateTo({

					url: "/pages/work/repairFinish?id=" + id + "&index=" + index,
				});
			},
			change1(item) {
				// alert(this.value1);
				console.log(item);
				this.search();
				// alert(123);
			},
			change2(item) {
				// alert(this.indexList.length);
				console.log(item);
				if (this.indexList.length > 0) {

					this.search()
				}

			},
			change3(item) {
				this.search()
			
			},
			change4(item) {
				// alert(this.indexList.length);
				console.log(item);
				if(item.text=="自定义日期范围"){
					this.show=true;
					return
				}else{
					// if(this.indexList.length>0){
						this.time='';
					   this.search()	
					// }
				}
				// if(this.indexList.length>0){
				// 	this.time='';
				//    this.search()	
				// }
				
			},
			scrolltolower() {
				this.loadmore()
			},
			search() {

				this.page = 0;
				if (this.indexList.length > 0) {
					this.indexList = []
				}
				
				//this.indexList=[];
				this.loadmore()
			},
			loadmore() {
				if (this.value2 == "") {
					this.value2 = "create_time desc";
				}
				if(this.all=="all"&&this.group_id==2){
								this.value1 = this.option[0]['value'];
							}
				console.log(this.value1);
				// alert(this.value2);
				this.page++;
				// this.indexList=[];
				var page = this.page;
				var limit = 5;
				// if(page>1){
				// 	return;
				// }
				uni.$u.http.get('https://wdzbx.zsbike.com.cn:10787/api.v1/repairList?limit=' + limit + '&page=' + page +
					"&userid=" + this.userid + "&condition=" + this.value1 + "&order=" + this.value2 + "&org=" + this
					.value3+"&all="+this.all+"&group_id="+this.group_id+"&time="+this.time, ).then(res => {
					if (res.data.Status == 1) {
						let arr = res.data.Data;
						for (let item of arr) {
							for (let key in item) {
							 console.log(item[key]) // foo, bar
							 if(item[key] == null){
								 item[key]="";
							 }
							}
							this.indexList.push(item);
						}
						this.title="共"+res.data.Total+"条记录";
						this.list1 = 1;

					} else {
						if (this.indexList.length < 1) {
							this.list1 = 0;
							console.log(this.page);
							console.log(this.indexList);
						} else {
							this.page--;
							this.list1 = 1;
						}
					}

				}).catch(err => {

				})

				// for (let i = 0; i < 30; i++) {
				// 	this.indexList.push()
				// }
			},
			listdetail(index) {
				alert(index);
			},
		}
	}
</script>